﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Collections;

using XJX.BusinessLayer;

namespace XJX.Page
{
    /// <summary>
    ///Family 的摘要说明
    /// </summary>
    public class Evaluate
    {
        public Evaluate()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        //添加书评
        public static bool Add_New_Evaluate(string BID, string UID, string Econtent, int Egrade, out int ReturnValue, out string ReturnFieldValue)
        {
            bool b;

            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Evaluate bs = new XJX.BusinessLayer.Evaluate(str);

            try
            {
                b = bs.Add_New_Evaluate(BID, UID, Econtent, Egrade, out ReturnValue, out ReturnFieldValue);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }

        

        //获取一本书的所有书评
        public static string Get_One_Book_Evaluate_From_BID(string BID, int PageIndex, int PageSize)
        {
            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Evaluate es = new XJX.BusinessLayer.Evaluate(str);

            Hashtable ht = es.Get_One_Book_Evaluate_From_BID(BID, PageIndex, PageSize);
            return XJX.BusinessLayer.JSON.Encode(ht);
        }


        //屏敝一条书评
        public static bool Shielding_One_Evaluate_From_EID(string EID)
        {
            bool b;

            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Evaluate bs = new XJX.BusinessLayer.Evaluate(str);

            try
            {
                b = bs.Shielding_One_Evaluate_From_EID(EID);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        //添加内容评价
        public static bool Ev_Add_New_Evaluate
            (
            string ItemName,
            string ParentID,
            string UID,
            string Content,
            out int ReturnValue,
            out string ReturnFieldValue
            )
        {
            bool b;

            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Evaluate bs = new XJX.BusinessLayer.Evaluate(str);

            try
            {
                b = bs.Ev_Add_New_Evaluate(ItemName,ParentID, UID, Content, out ReturnValue, out ReturnFieldValue);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }


        //删除内容的一条评价记录
        public static bool Ev_Del_One_ContentEvaluate_From_ID(string ID, string UID)
        {
            bool b;

            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Evaluate bs = new XJX.BusinessLayer.Evaluate(str);

            try
            {
                b = bs.Ev_Del_One_ContentEvaluate_From_ID(ID, UID);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }

        //添加点赞,或者去掉点赞
        public static bool Ev_Add_New_Credit
            (
            string ItemName,
            string ParentID,
            string UID
            )
        {
            bool b;

            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Evaluate bs = new XJX.BusinessLayer.Evaluate(str);

            try
            {
                b = bs.Ev_Add_New_Credit(ItemName, ParentID, UID);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return b;
        }

        //某个家庭针对某主题发表的所有回复内容
        public static string Ev_Get_One_Family_ContentEvaluate_By_UID
            (
            string ItemName,
            string ParentID,
            string UID,

            int PageIndex,
            int PageSize
            )
        {
            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Evaluate bs = new XJX.BusinessLayer.Evaluate(str);

            Hashtable ht = bs.Ev_Get_One_Family_ContentEvaluate_By_UID(ItemName, ParentID, UID, PageIndex, PageSize);
            return XJX.BusinessLayer.JSON.Encode(ht);
        }



        //一般用户或者管理员获取某主题回复内容列表
        public static string Ev_Search_ContentEvaluate_List
            (
            string ItemName,
            string ParentID,
            string IsAll,

            int PageIndex,
            int PageSize
            )
        {
            string str = System.Configuration.ConfigurationManager.ConnectionStrings["DataConn"].ConnectionString;

            XJX.BusinessLayer.Evaluate bs = new XJX.BusinessLayer.Evaluate(str);

            Hashtable ht = bs.Ev_Search_ContentEvaluate_List(ItemName, ParentID, IsAll, PageIndex, PageSize);
            return XJX.BusinessLayer.JSON.Encode(ht);
        }

    }

    ////////////////////////////////////////////////////////////////////////////以下系统信息类属性

    public class EvaluateInfo
    {
        public int ID;
        public string Sname;
        public string RXNF;
        public string CID;
        public string Sex;
        public string Fname;
        public string Mobile;
        public string PWD;
        public string Flag;
        public int Lnum;
        public string UID;
        public int Bnum;
    }

}